package com.easy;

/**
 * Created by Lxk on 2019/3/16.
 */
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}

public class Solution61 {
    public ListNode rotateRight(ListNode head, int k) {
        if(head==null){
            return null;
        }
        int count = 1;
        ListNode cur = head;
        while(cur.next!=null){
            cur = cur.next;
            count++;
        }
        cur.next = head;
        k = k % count;
        int step = count - k -1;
        while(step!=0){
            head = head.next;
            step--;
        }
        cur = head;
        head = cur.next;
        cur.next = null;
        return head;
    }
}
